// pages/chat-record/chat-record.js
import http from "../../utils/http.js";
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    chatRecords:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      userId:app.globalData.userInfo.id
    })
    http.chatLogs(options.id,(res)=>{
      console.log(res);
      let customer = res.data.chat.customer;
      let fortuneteller = res.data.chat.fortuneteller;
      let chatRecords = res.data.list;
      for(let i = 0; i < chatRecords.length ; i ++){
        if(chatRecords[i].receiver_id == customer.id){
          chatRecords[i].user = customer;
        } else {
          chatRecords[i].user = fortuneteller;
        }
      }
      that.setData({
        chatRecords:chatRecords
      });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})